window.onload = function () {
    authenticate();
    var type = location.href.split("/");
    type = type[type.length - 1];
    if (type === "all") {
        $(".titleName").text("所有");
        $(".all").addClass("active_");
        fillingMain(1, "questions", 10)
        fillingHotTopic("all",10);
    } else if (type === "study") {
        $(".titleName").text("学习");
        fillingMain(1, "study", 10);
        $(".study").addClass("active_");
        fillingHotTopic("study",10);
    } else if (type === "life") {
        $(".titleName").text("生活");
        fillingMain(1, "life", 10);
        $(".life").addClass("active_");
        fillingHotTopic("life",10);
    } else if (type === "resource") {
        $(".titleName").text("资源");
        fillingMain(1, "resource", 10);
        $(".resource").addClass("active_");
        fillingHotTopic("resource",10);
    } else if (type === "news") {
        $(".titleName").text("新闻资讯");
        $(".news").addClass("active_");
        fillingNews(1,"news",10);
        fillingPagination(1, "news", 10)
        fillingHotTopicNews(6);
    }
};
function fillingNews(page,type,size){
    $.ajax({
        url: "/news/"+page+"/"+size,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        type: "POST",
        success: function (response) {
            appendNews(response.data);
            fillingPagination(page,"news",size)
        },
        error: function (request) {

        }
    });
}
function appendNews(data) {
    console.log(data);
    $(".main").empty();
    for (var i = 0; i < data.length; i++) {
        var info = "<article class=\"excerpt excerpt-1\" style=\"height: 127px;\">\n" +
            "                    <a class=\"focus\" href=\"" + "/news/"+data[i].id + "\" title=\""+data[i].title+"\" target=\"_blank\">\n" +
            "                        <img class=\"thumb\"  data-original=\"#\"\n" +
            "                             src=\"" + data[i].imageUrl + "\" alt=\"###\" style=\"display: inline;\">" + "</a>\n" +
            "                    <header>\n" +
            "                        <h2><a href=\"" + "/news/" + data[i].id + "\" title=\"#\" target=\"_blank\">" + data[i].title + "</a>\n" +
            "                        </h2>\n" +
            "                    </header>\n" +
            "                    <p class=\"meta\">\n" +
            "                        <time class=\"time\"><i class=\"glyphicon glyphicon-time\"></i>" + data[i].publishTime + "</time>\n" +
            "                        <span class=\"views\"><i class=\"glyphicon glyphicon-eye-open\"></i>" + data[i].readCount + "</span>\n" +
            "                        <a class=\"comment\" href=\"##comment\" title=\"评论\" target=\"_blank\">\n" +
            "                            <i class=\"glyphicon glyphicon-comment\"></i>\n" +
            "                            4\n" +
            "                        </a>\n" +
            "                    </p>\n" +
            "                    <p class=\"note\">" + data[i].content + "</p>\n" +
            "                </article>";
        $(".main").append(info);
    }
}
